<template>
  <div>
    <FormRender
      ref="form"
      :pageConfig="formOpts.runjs"
      :models="formOpts"
      :datas="flowOpts"
      :formDataChange="formDataChange"
      :flowInfo="flowInfo"
      :options="options"
      :defKey="flowOpts.defKey"
      :flowComment="formOpts.flowComment"
      :taskId="flowOpts.taskId"
      :appName="formOpts.appName"
      :formUrl="formUrl"
      :defid="flowOpts.flowConfig && flowOpts.flowConfig.defId"
      :showNextNode="flowOpts.flowConfig && flowOpts.flowConfig.needSelectNode"
      :oneLegKicking="flowOpts.flowConfig && flowOpts.flowConfig.oneLegKicking"
      :showNextAssignees="flowOpts.flowConfig && flowOpts.flowConfig.needSelectAssignees"
      :multiple = "flowOpts.flowConfig && !flowOpts.flowConfig.singleSelectAssignees"
      :defaultCustom = "flowOpts.flowConfig && !flowOpts.flowConfig.cannotSelectInAll"
      @change="formChange"
      @subform-change="subformChange"
      @subgrid-change="subgridChange"
      @commentp-change="commentpChange"
    />
    <iframe name="upload_pipe" id="upload_pipe" style="display:none" title="上传"></iframe>
    <form :action="submitURL" enctype="multipart/form-data" method="POST" ref="multipart_form" target="upload_pipe" style="display:none">
      <input type="hidden" name="data" ref="multipart_data">
    </form>
  </div>
</template>

<script>
import FormRender from 'components/form-render'

export default {
  data() {
    return {
      formDataChange: null,
      submitURL: window.submitURL,
    }
  },
  props: {
    flowOpts: Object,
    formOpts: Object,
    otherOpts: Object,
    itemData: Object,
    flowInfo: Object,
    formContentRef: Object,
    formFooterRef: Object,
    options: Object,
    formUrl: String
  },
  computed: {

  },
  methods: {
    formChange(value, type) {
      if(type && type === "initData"){
        this.$refs.form.refresh(value)
      }else{
        this.$emit("on-change",value)
      }
    },
    subformChange(event, value) {
      //针对业务字段《设置更新下一步环节》 进行处理
      const target = $(event.target)
      const curName = target.data('name')
      // console.log('form change', target.data('name'), target.val())
      this.formOpts.meta.forEach(element => {
        if(element.name === curName && element.nextNode === "true"){
          this.$refs.form.refresh(value)
        }
      })
    },
    subgridChange(event, tableMeta, value) {
      //针对业务字段《设置更新下一步环节》 进行处理
      const target = $(event.target)
      const curName = target.data('name')
      // console.log('form change', target.data('name'), target.val())
      tableMeta.forEach(element => {
        if(element.name === curName && element.nextNode === "true"){
          this.$refs.form.refresh(value)
        }
      })
    },
    commentpChange(obj, nextFlag, value) {
      if(nextFlag){
        this.$refs.form.refresh(value)
      }
    }
  },
  mounted() {
  },
  components: {
    /* eslint-disable-next-line */
    FormRender
  }
}
</script>
